{% extends 'base.html' %}
{% load helpers %}
{% load form_helpers %}
{% load render_table from django_tables2 %}

{% block title %}Editing {{ objs_count }} {{ obj_type_plural|bettertitle }}{% endblock %}

{% block content %}
    <form action="" method="post" class="h-100 vstack">
        {% csrf_token %}
        {% if request.POST.return_url %}
            <input type="hidden" name="return_url" value="{{ request.POST.return_url }}" />
        {% endif %}
        {% for field in form.hidden_fields %}
            {{ field }}
        {% endfor %}
        <div class="row justify-content-center align-content-start flex-fill">
            {% if form.errors %}
                <div class="card border-danger">
                    <div class="card-header bg-danger-subtle border-danger text-body">
                        <strong>Errors</strong>
                    </div>
                    <div class="card-body">
                        {{ form.non_field_errors }}
                        {% for field in form %}
                            {% if field.errors %}
                                <strong>{{ field.label }}</strong>: {{ field.errors }}
                            {% endif %}
                        {% endfor %}
                    </div>
                </div>
            {% endif %}
            {% if table %}
                <div class="col-lg-8">
                    <div class="card">
                        <div class="table-responsive">
                            {% render_table table 'inc/table.html' %}
                        </div>
                    </div>
                </div>
            {% endif %}
            <div class="{% if table %}col-lg-4{% else %}col-lg-8 col-md-12{% endif %}">
                <div class="card">
                    <div class="card-header"><strong>{% block form_title %}Attributes{% endblock %}</strong></div>
                    <div class="card-body">
                        {% block form_fields %}
                            {% for field in form.visible_fields %}
                                {% if field.name in form.nullable_fields %}
                                    {% render_field field bulk_nullable=True %}
                                {% elif field.name == "object_note" %}
                                    {% if perms.extras.add_note %}
                                        {% render_field field %}
                                    {% endif %}
                                {% else %}
                                    {% render_field field %}
                                {% endif %}
                            {% endfor %}
                        {% endblock %}
                    </div>
                </div>
            </div>
        </div>
        <div class="nb-form-sticky-footer">
            <button type="submit" name="_apply" class="btn btn-primary">
                <span aria-hidden="true" class="mdi mdi-check me-4"></span><!--
                -->Apply
            </button>
            <a href="{{ return_url }}" class="btn btn-secondary">
                <span aria-hidden="true" class="mdi mdi-close me-4"></span><!--
                -->Cancel
            </a>
        </div>
    </form>
{% endblock %}
